import threading
import time

threads = []


class NewThread(threading.Thread):
    def __init__(self, *args, **kwargs):
        threading.Thread.__init__(self)

    def run(self):
        pass


# to define a function to process in sub thread.
def thread_func(*args, **kwargs):
    print("The sub thread  %s is running ..." % (str(threading.current_thread().ident)))
    time.sleep(3)


# Way1 to use Thread class to create new thread.
for i in range(5):
    thread = threading.Thread(target=thread_func)
    thread.setDaemon(True)
    thread.start()
    threads.append(thread)

# wait for the sub thread to terminate
for t in threads:
    t.join()
    print("The thread %s is terminated" % (str(t.ident)))
